package com.touch.app.controller;

import com.touch.app.common.domain.Ask;
import com.touch.app.common.domain.ChatGPTRequest;
import com.touch.app.common.domain.ChatGPTResponse;
import com.touch.app.common.util.R;
import com.touch.app.service.ChatGPTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/api/openai")
public class ChatGPTController {

    @Autowired
    private ChatGPTService chatGPTService;

    @PostMapping("/ask")
    @ResponseBody
    public R askQuestion(@RequestBody Ask ask) {
        return R.ok("success", chatGPTService.askQuestion(ask));
    }

    @PostMapping("/request")
    @ResponseBody
    public ChatGPTResponse request(@RequestBody ChatGPTRequest chatGPTRequest, HttpServletRequest request) {
        return chatGPTService.request(chatGPTRequest, request);
    }
}
